package com.jdz.gxq.info.admin.landclear.service;

import java.util.List;
import java.util.Map;

import com.jdz.gxq.info.admin.landclear.bo.Landclear;

import jp.terasoluna.fw.dao.QueryDAO;
import jp.terasoluna.fw.dao.UpdateDAO;

public class LandclearServiceImpl implements LandclearService {
	
	private QueryDAO queryDAO = null;
	
	private UpdateDAO updateDAO = null;
	
	/**
	 * Landclear检索分页用，查询记录条数
	 * @return
	 */
	public int getLandclearsCount(String enterpriseName) {
		
		int totalCount = queryDAO.executeForObject("landclear.getLandclearsCount",
				enterpriseName, Integer.class);
		
		return totalCount;
	}
	
	/**
	 * Landclear检索
	 * @return
	 */
	public List<Landclear> getLandclears(Map<String, Object> params) {
		
		return queryDAO.executeForObjectList("landclear.getLandclears", params);
	}
	
	/**
	 * 追加Landclear
	 * @param landclear
	 */
	public void insertLandclear(Landclear landclear) {
		
		updateDAO.execute("landclear.insertLandclear", landclear);
	}
	
	/**
	 * 更新Landclear
	 * @param landclear
	 */
	public void updateLandclear(Landclear landclear) {
		
		updateDAO.execute("landclear.updateLandclear", landclear);
	}
	
	/**
	 * 通过id得到landclear
	 * @param id
	 * @return
	 */
	public Landclear getLandclearById(int id) {

		Landclear landclear = queryDAO.executeForObject("landclear.getLandclearById",
				id, Landclear.class);
		
		return landclear;
	}
	
	/**
	 * 删除Landclear
	 * @param landclear
	 */
	public void deleteLandclear(int id) {
		
		updateDAO.execute("landclear.deleteLandclearById", id);
	}
	
	/**
	 * 验证landclearName是否重复
	 * flag: 1 追加时验证
	 * flag: 2 更新时验证
	 */
	public boolean checkLandclearName(Landclear paramLandclear, int flag) {
		
		Landclear landclear = queryDAO.executeForObject("landclear.getLandclearByName",
				paramLandclear.getEnterpriseName(), Landclear.class);

		if (landclear == null) {
			return true;
		}
		
		// 更新验证，查出来的数据是不是本身
		if (flag == 2) {
			
			if (landclear.getId() == paramLandclear.getId()) {
				return true;
			}
		}
		
		return false;
	}

	public void setQueryDAO(QueryDAO queryDAO) {
		this.queryDAO = queryDAO;
	}

	public void setUpdateDAO(UpdateDAO updateDAO) {
		this.updateDAO = updateDAO;
	}
	
	
}
